home *** CD-ROM | disk | FTP | other *** search
/ Developer Source 17 / Developer Source Volume 17 (I-MODE Publications, Inc.)(2000).iso / dobbs / feb97 / meyet101.gif < prev    next >
Graphics Interchange Format  |  1998-02-10  |  116KB  |  618x526  |  4-bit (16 colors)
Labels: text | screenshot | document | font | menu | number
OCR: Rule Book Item Description Rule Book Item Description (a) Use const instead of #define for constants at global 17ª Have operators like +-/* retum an object, not a and file scope. reference. 2 3 Use new-style casts Instead of C-style casts. Don't treat a pointer to Derived Jas a pointer to Base]. 17b 18 M . 6 19 25 And make those retum values const .. 20 M 33 Don't overload on a pointer and an int. M . 24 Make nonleaf classes abstract. Avoid gratuitous use of virtual inheritance; that is, E 5 Use the same form for calls to new and delete. {In make sure there are at least two inheritance general, this calls for dynamic analysis, but static paths to each virtual base class. analysis can catch some special cases; calls to new in constructors and to delete in destructors, (e) kx example.) 21 When the result of a new expression in a constructor 29 Don't retum pointers/references to internal dats 5 E 30 structures unless they are pointers references to is stored in a dumb pointer class member, make sure const. Golato is called on that member in the destructor." 22 M : 26 Never defne a static variable inside a nonmember E 9 Avoid hiding the default signature for operator new infine function unless the function is declared and operator delete. extern. (Note: In July 1996; changes to the nascent standard for ANSIOSO C++ obviated the need for this rufe, at least on paper. However, the 70 Doclare a copy constructor for each class declaring need still exists in practice, because many compilers continue to heed the older rules that 1 :a pointer data member. Declare an assignment operator for each class can lead to duplicated variables in Inline 8 .12 declaring a pointer data member. nonmember functions.) Initialize each class date member via the member 23 Avoid use of " .. . in function parameter lists. E initialization Est .. 13 List members in a member initla zation list in an order consistent with the order in which they are Don't redefine an inherited nonvirtual function. actually initialized, E Don't redeline an inherited default parameter value. 10 11 14 15 Make destructors virtual in base classes. Have the de nition of operators retum a reference to (g) *this (Note: This says nothing about declarations.] 28 ME 6 Avoid use of user-defined conversion operators 122 12b 16 Assign to every local date member inside operator -. {nonexplicit sing's-argument constructors and Call a base class operator- from a derived class operator= Use the member initle zation list to ensure that a 27 28 M 7 implicit type conversion operators). 12 6 Don't overioad &8, Il; or Make sure operatora ++ and -- have the correct base class copy constructor is called from a derived class copy constructor. 29 .M return type- Use prefix ++ and -- when the result of the 13 Don't cal virtuel functions in constructors or increment or decrement expression is unused. destructors. M 22 Dociare cos if you declaro binary operator (For. example, declare += # you declare +, declare == if you declare -). One way to satisly this E /19 Use nonmember functions for binary operations ske constraint is by providing a template that yiokis +"/" when a class has a converting constructor. the appropriate function. 15 :16 Avoid public data mombers; Use pass-by-ref-to-const instead of pass-by-value where both are valid and the fomer Is likely to be M Prevent exceptions from leaving destrucks. Catch exceptions by reference, Table 1: Benchmark rules, (a) General: (b) use of new and delete; (c) constructors/destructors/assignment; (d) design; (e) implementation; (f) inheritance; (g) operators; (b) exceptions.